<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:viewParam name="param" value="#{lancamentoProducaoBean.param}"/>
			</f:metadata>
			
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="#{msg['massai.comum.pesquisar']}" ajax="false" 
						immediate="true" action="planilhaProducaoPesquisa" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            
		            <p:commandButton value="#{msg['massai.planilhaProducao.aprovar']}" ajax="false" 
						immediate="true" actionListener="#{lancamentoProducaoBean.aprovarPlanilha()}" 
						disabled="#{lancamentoProducaoBean.verificaStatus() or lancamentoProducaoBean.obraBloquada}" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            
		            <p:commandButton value="#{msg['massai.planilhaProducao.reprovar']}" ajax="false" 
						immediate="true" actionListener="#{lancamentoProducaoBean.reprovarPlanilha()}" 
						disabled="#{lancamentoProducaoBean.verificaStatus() or lancamentoProducaoBean.obraBloquada}" />
				</f:facet>
			</p:toolbar>
			<p:panel header="#{msg['massai.planilhaProducao.header']}">
				<h:panelGrid>
					<h:panelGrid columns="6">
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.codigo']}" for="codigo" />
							<p:inputText value="#{genericUtilBean.completarZerosEsquerda(lancamentoProducaoBean.planilha.id, 6)}" 
								id="codigo" label="#{msg['massai.planilhaProducao.codigo']}" style="width: 80px; text-align: right;"
								disabled="true" readonly="true" />
						</h:panelGrid>

						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.competencia']}" for="competencia" />
							<p:inputMask mask="99/9999" value="#{lancamentoProducaoBean.planilha.competencia}" 
								id="competencia" label="#{msg['massai.planilhaProducao.competencia']}" 
								style="width: 80px; text-align: right;" disabled="true" readonly="true"
								converter="competenciaConverter" />
						</h:panelGrid>

						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.dataCadastro']}" for="data" />
							<p:inputText value="#{lancamentoProducaoBean.planilha.dataCadastro}" 
								id="data" label="#{msg['massai.planilhaProducao.dataCadastro']}" 
								style="width: 100px; text-align: right;" disabled="true" readonly="true">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</p:inputText>
						</h:panelGrid>

						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.status']}" for="status" />
							<p:inputText value="#{lancamentoProducaoBean.planilha.status.descricao}" 
								id="status" label="#{msg['massai.planilhaProducao.status']}" 
								style="width: 104px;" disabled="true" readonly="true" />
						</h:panelGrid>

						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.tipoFolha']}" for="tipoFolha" />
							<p:inputText value="#{lancamentoProducaoBean.planilha.tipoFolha.descricao}" 
								id="tipoFolha" label="#{msg['massai.planilhaProducao.tipoFolha']}" 
								maxlength="10" style="width: 100px;" disabled="true" readonly="true" />
						</h:panelGrid>

						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.planilhaProducao.obra']}" for="obra" />
							<p:inputText 
								value="#{genericUtilBean.completarZerosEsquerda(lancamentoProducaoBean.planilha.obra.codigoColigada, 8)} - #{lancamentoProducaoBean.planilha.obra.codigoDepto} - #{lancamentoProducaoBean.planilha.obra.nomeFantasia ne null ? lancamentoProducaoBean.planilha.obra.nomeFantasia : lancamentoProducaoBean.planilha.obra.nome}" 
								id="obra" label="#{msg['massai.planilhaProducao.obra']}" 
								style="width: 300px;" disabled="true" readonly="true" />
						</h:panelGrid>
					</h:panelGrid>

					<h:panelGrid>
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.lancarServicoProducao.observacoesLancamento']}" for="observacoesLanc" />
							<p:inputTextarea value="#{lancamentoProducaoBean.planilha.observacao}" 
								id="observacoesLanc" label="#{msg['massai.planilhaProducao.observacoes']}" 
								disabled="true" readonly="true" rows="2" cols="120"/>
						</h:panelGrid>
					</h:panelGrid>

					<h:panelGrid>
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.lancarServicoProducao.observacoesAnalise']}" for="observacoesAnalise" />
							<p:inputTextarea 
								value="#{lancamentoProducaoBean.observacaoRevisao}" 
								id="observacoesAnalise" label="#{msg['massai.planilhaProducao.observacoes']}" 
								rows="2" cols="120" disabled="#{lancamentoProducaoBean.obraBloquada}" 
								readonly="#{lancamentoProducaoBean.obraBloquada}">
								<p:ajax event="blur" global="false" />
							</p:inputTextarea>
						</h:panelGrid>
					</h:panelGrid>

					<p:spacer height="20" />

					<p:panel header="#{msg['massai.lancarServicoProducao.lancamentosHeader']}"
						rendered="#{lancamentoProducaoBean.lancamentos.size() ne 0}">

						<ui:repeat var="lancamento" value="#{lancamentoProducaoBean.lancamentos}">

							<p:dataTable rendered="#{lancamentoProducaoBean.planilha.id ne null}" 
								value="#{lancamento.listaItensLancamento}" var="item">

								<f:facet name="header">
									<h:outputText value="#{lancamento.regime.descricao} - ( #{lancamento.funcionario.codTotvs} - #{lancamento.funcionario.funcao} ) #{lancamento.funcionario.nome}" />
								</f:facet>

								<p:column headerText="#{msg['massai.lancarServicoProducao.itemServiço']}" width="300">
									<h:outputText 
										value="#{item.itemPlanilha.itemServico.nivel} - #{item.itemPlanilha.itemServico.descricao}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.itemServico.unidadeMedida']}">
									<h:outputText value="#{item.itemPlanilha.itemServico.unidadeMedida ne null ? item.itemPlanilha.itemServico.unidadeMedida.sigla : '-'}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.quantidade']}">
									<h:outputText value="#{item.quantidade}">
										<f:convertNumber pattern="#,##0.00" 
											maxFractionDigits="2" minFractionDigits="2" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorUnit']}">
									<h:outputText value="#{item.itemPlanilha.valor}">
										<f:convertNumber pattern="R$ #,##0.00" currencySymbol="R$" 
											maxFractionDigits="4" minFractionDigits="4" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorTotal']}">
									<h:outputText value="#{item.total}">
										<f:convertNumber pattern="R$ #,##0.00" currencySymbol="R$" 
											maxFractionDigits="2" minFractionDigits="2" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorPerc']}">
									<h:outputText value="#{item.valorPercent}">
										<f:convertNumber pattern="#,##0.0000%" 
											maxFractionDigits="4" minFractionDigits="4" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.itemOrcamento']}">
									<h:outputText value="#{item.itemOrcamento.cdReferencia}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.observacoes']}">
									<h:outputText value="#{item.observacao}" />
								</p:column>
								
								<p:columnGroup type="footer">
						            <p:row>
						                <p:column colspan="4" style="text-align:right" footerText="#{msg['massai.lancarServicoProducao.totais']}" />
						                <p:column footerText="#{lancamentoProducaoBean.decimalFormat('R$ #,##0.00', lancamento.totalValor)}" />
						                <p:column style="text-align: left" footerText="#{lancamentoProducaoBean.decimalFormat('#,##0.0000%', lancamento.totalPercent)}" />
						                <p:column colspan="2" />
						            </p:row>
						        </p:columnGroup>
							</p:dataTable>
							
							<p:spacer height="20" />

						</ui:repeat>
					</p:panel>
				</h:panelGrid>
			</p:panel>
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="#{msg['massai.comum.pesquisar']}" ajax="false" 
						immediate="true" action="planilhaProducaoPesquisa" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            
		            <p:commandButton value="#{msg['massai.planilhaProducao.aprovar']}" ajax="false" 
						immediate="true" actionListener="#{lancamentoProducaoBean.aprovarPlanilha()}" 
						disabled="#{lancamentoProducaoBean.verificaStatus() or lancamentoProducaoBean.obraBloquada}" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            
		            <p:commandButton value="#{msg['massai.planilhaProducao.reprovar']}" ajax="false" 
						immediate="true" actionListener="#{lancamentoProducaoBean.reprovarPlanilha()}" 
						disabled="#{lancamentoProducaoBean.verificaStatus() or lancamentoProducaoBean.obraBloquada}" />
				</f:facet>
			</p:toolbar>
		</h:form>
	</ui:define>
</ui:composition>
</html>